class Result {
  constructor(ctx, msg = 'success', code = 200, data = null, extra = null) {
    this.msg = msg;
    this.code = code;
    this.data = data;
    this.extra = extra;
    this.ctx = ctx;
  }

  // 统一返回json格式
  answer() {
    this.ctx.body = {
      msg: this.msg,
      data: this.data,
      extra: this.extra
    }
    this.ctx.status = this.code
  }
}

module.exports = Result